<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增催款申请单')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-from-add"  th:object="${pId}">
            <div class="form-group">
                <label class="col-sm-3 control-label">劳务金额：</label>
                <div class="col-sm-8">
                    <input id="dCost" name="dCost" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">劳务合同：</label>
                <div class="col-sm-8">
                    <input id="aLabor" name="aLabor" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">供应商名称/应付单位名称：</label>
                <div class="col-sm-8">
                    <input id="dSupplierName" name="dSupplierName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">申请内容：</label>
                <div class="col-sm-8">
                    <input id="dApplicationContent" name="dApplicationContent" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">申请时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="dCreateTime" name="dCreateTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">总项目关联：</label>
                <div class="col-sm-8">
                    <input id="pId" name="pId" class="form-control" type="text"  th:value="${pId}">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">照片：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="dFile" class="form-control" type="file" required>
                </div>
            </div>

            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">申请状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <div class="radio-box">
                            <select id="aStatus" name="aStatus" th:with="type=${@dict.getType('dept_status')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">审批意见：</label>
                <div class="col-sm-8">
                    <input id="aOpinion" name="aOpinion" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "ruoyi/from"
        $("#form-from-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('dCost', $("#dCost").val());
            formData.append('aOpinion', $("#aOpinion").val());
            formData.append('aStatus', $("#aStatus").val());
            formData.append('pId', $("#pId").val());
            formData.append('dCreateTime', $("#dCreateTime").val());
            formData.append('dApplicationContent', $("#dApplicationContent").val());
            formData.append('dCost', $("#dCost").val());
            formData.append('dSupplierName', $("#dSupplierName").val());
            formData.append('dProposer', $("#dProposer").val());
            formData.append('aLabor', $("#aLabor").val());
            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: prefix + "/add/",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }

        $("input[name='dCreateTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>